<template>
  <div>
    <script :id=id type="text/plain"></script>
  </div>
</template>
<script>
  export default {
    name: 'UE',
    data () {
      return {
        editor: null
      }
    },
    props: {
      defaultMsg: {
        type: String
      },
      config: {
        type: Object
      },
      id: {
        type: String
      },
    },
    mounted() {
      const _this = this;
       let flag = true;
      this.editor = UE.getEditor(this.id, this.config); // 初始化UE
      this.editor.addListener("ready", function () {
        _this.editor.setContent(_this.defaultMsg); // 确保UE加载完成后，放入内容。
      });
    },
    methods: {
      // 获取内容方法
      getUEContent() { 
        return this.editor.getContent()
      },
      //UE监听
      listenAfterSetContent() {
        const _this = this;
        this.editor.addListener( 'afterSetContent', function( editor ) {
          setTimeout(function(){
              setTimeout(function(){
                _this.editor.setHide();
              },200)
              _this.editor.execCommand('print')
            },1000)
        });
      },
      // 打印方法
      getUEexecCommand() { 
        const _this = this;
        setTimeout(function(){
          return _this.editor.execCommand('print')
        },2000)
      }
    },
    destroyed() {
      this.editor.destroy();
    }
  }
</script>
